﻿using System;
using System.Collections.Generic;
using System.Data.SQLite;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

public static class DBHelper
{
    public static string dbPath = "words.db";

    public static void InitializeDatabase()
    {
        if (!File.Exists(dbPath))
        {
            SQLiteConnection.CreateFile(dbPath);

            using (var conn = new SQLiteConnection($"Data Source={dbPath}"))
            {
                conn.Open();

                string createTableSql = @"
                    CREATE TABLE Words (
                        id INTEGER PRIMARY KEY AUTOINCREMENT,
                        EnglishWord TEXT NOT NULL,
                        ChineseMeaning TEXT NOT NULL
                    );";
                var cmd = new SQLiteCommand(createTableSql, conn);
                cmd.ExecuteNonQuery();

                // 插入初始单词
                string insertSql = @"
                    INSERT INTO Words (EnglishWord, ChineseMeaning) VALUES 
                    ('apple', '苹果'),
                    ('book', '书'),
                    ('computer', '电脑'),
                    ('school', '学校'),
                    ('banana', '香蕉');";
                cmd = new SQLiteCommand(insertSql, conn);
                cmd.ExecuteNonQuery();
            }
        }
    }
}
